package chai.ningning.dev;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = { "/dispatcher/*", "*.sb" })
public class DispatcherServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
			throws ServletException, IOException {
		System.out.println("GET");
		// 在控制台（Console）中输出信息
		System.out.println("dispatcher servlet : doGet");
		// 获得可以向响应对象中输出数据的字符输出流
		PrintWriter out = resp.getWriter();
		// 向响应对象中输出HTML片段（最终发送到Web客户端）
		out.println("<h1 align='center'>I am a dispatcher servlet .</h1>");
		out.println("<h3 align='center'>request method : GET .</h3>");
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) 
			throws ServletException, IOException {
		System.out.println("POST");
		// 在控制台（Console）中输出信息
		System.out.println("dispatcher servlet : doPost");
		// 获得可以向响应对象中输出数据的字符输出流
		PrintWriter out = resp.getWriter();
		// 向响应对象中输出HTML片段（最终发送到Web客户端）
		out.println("<h1 align='center'>I am a dispatcher servlet .</h1>");
		out.println("<h3 align='center'>request method : POST .</h3>");
	}

}
